package com.ruoyi.project.infobaseprojectindex.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.infobaseprojectindex.vo.InfoBaseProjectIndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.infobaseprojectindex.mapper.InfoBaseProjectIndexMapper;
import com.ruoyi.project.infobaseprojectindex.domain.InfoBaseProjectIndex;
import com.ruoyi.project.infobaseprojectindex.service.IInfoBaseProjectIndexService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * 基础库-项目库-指标Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-11
 */
@Service
public class InfoBaseProjectIndexServiceImpl implements IInfoBaseProjectIndexService {
    @Autowired
    private InfoBaseProjectIndexMapper infoBaseProjectIndexMapper;

    /**
     * 查询基础库-项目库-指标
     *
     * @param id 基础库-项目库-指标主键
     * @return 基础库-项目库-指标
     */
    @Override
    public InfoBaseProjectIndex selectInfoBaseProjectIndexById(Long id) {
        return infoBaseProjectIndexMapper.selectInfoBaseProjectIndexById(id);
    }

    /**
     * 查询基础库-项目库-指标列表
     *
     * @param infoBaseProjectIndex 基础库-项目库-指标
     * @return 基础库-项目库-指标
     */
    @Override
    public List<InfoBaseProjectIndex> selectInfoBaseProjectIndexList(InfoBaseProjectIndex infoBaseProjectIndex) {
        return infoBaseProjectIndexMapper.selectInfoBaseProjectIndexList(infoBaseProjectIndex);
    }

    /**
     * 新增基础库-项目库-指标
     *
     * @param infoBaseProjectIndex 基础库-项目库-指标
     * @return 结果
     */
    @Override
    public int insertInfoBaseProjectIndex(InfoBaseProjectIndex infoBaseProjectIndex) {
        infoBaseProjectIndex.setCreateTime(DateUtils.getNowDate());
        return infoBaseProjectIndexMapper.insertInfoBaseProjectIndex(infoBaseProjectIndex);
    }

    /**
     * 修改基础库-项目库-指标
     *
     * @param infoBaseProjectIndex 基础库-项目库-指标
     * @return 结果
     */
    @Override
    public int updateInfoBaseProjectIndex(InfoBaseProjectIndex infoBaseProjectIndex) {
        infoBaseProjectIndex.setUpdateTime(DateUtils.getNowDate());
        return infoBaseProjectIndexMapper.updateInfoBaseProjectIndex(infoBaseProjectIndex);
    }

    /**
     * 批量删除基础库-项目库-指标
     *
     * @param ids 需要删除的基础库-项目库-指标主键
     * @return 结果
     */
    @Override
    public int deleteInfoBaseProjectIndexByIds(Long[] ids) {
        return infoBaseProjectIndexMapper.deleteInfoBaseProjectIndexByIds(ids);
    }

    /**
     * 删除基础库-项目库-指标信息
     *
     * @param id 基础库-项目库-指标主键
     * @return 结果
     */
    @Override
    public int deleteInfoBaseProjectIndexById(Long id) {
        return infoBaseProjectIndexMapper.deleteInfoBaseProjectIndexById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchInsertBaseProjectIndex(InfoBaseProjectIndexVo infoBaseProjectIndexVo) {
        try {
            List<InfoBaseProjectIndex> infoBaseProjectIndices = infoBaseProjectIndexVo.getProjectIndexList();
            for (InfoBaseProjectIndex infoBaseProjectIndex : infoBaseProjectIndices) {
                infoBaseProjectIndex.setProjectId(infoBaseProjectIndexVo.getProjectId());
                infoBaseProjectIndexMapper.insertInfoBaseProjectIndex(infoBaseProjectIndex);
            }
            return 1;
        } catch (Exception e) {
            System.out.println(e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
    }

    @Override
    public List<InfoBaseProjectIndex> selectInfoBaseProjectIndexByIds(Long projectId) {
        return infoBaseProjectIndexMapper.selectInfoBaseProjectIndexByIds(projectId);
    }

}
